using AbpLocalization.ApiHost.Localization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Localization;

namespace AbpLocalization.ApiHost.Controllers
{
    [ApiController]
    [Route("test/localize")]
    public class TestLocalizationController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<TestLocalizationController> _logger;
        private readonly IStringLocalizer<PerryLocalizationResource> _localizer;

        public TestLocalizationController(
            ILogger<TestLocalizationController> logger,
            IStringLocalizer<PerryLocalizationResource> localizer
            )
        {
            _logger = logger;
            _localizer = localizer;
        }

        [HttpGet]
        public async Task<string> TestAsync()
        {
            await Task.CompletedTask;
            var orderNo = "20211110000012";

            CultureHelper.Use("en");

            if (true) {
                var errCode = "Exp_Order_NotFound";
                var errMsg = _localizer.GetString(errCode, orderNo);
                throw new BusinessException(message:errMsg,code: errCode);
            }

            return orderNo;
        }
    }
}